<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_block_TranslateMenuAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$formValues = $this->getFormValues("form");
		
		$menu = $this->getDocumentProvider()->getByUniqueId($this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));
		
		$originalMenu = $menu->getVODocument();
		
		if(count($formValues) > 0)
		{					
			$menu	->setPublicationstatus("PUBLISHED")
					->setAuthor($this->getUser()->getLogin())
					->setLabel($formValues["label"])
					->save(false);
			
			$relManager = f_relation_Manager::getInstance();
			
			$parentId = $relManager->getParentId($originalMenu->getUniqueId(), "menus", $originalMenu->getLang());
			
			$parent = $this->getDocumentProvider()->getByUniqueId($parentId['parent_id'], $menu->getLang());
			
			$parent->addMenus($menu)->save(false);
			
			return "redirectUrl=".$menu->getEditUrl($menu->getLang());
		}
		else
		{
			$menu->setLabel($originalMenu->getLabel()." (".$menu->getLang().")");
		}		
		
		$this->addToModel("menu", $menu);
		$this->setView('success');
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "website_Translation"));
	}
}